home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / GDIMETA.PAK / INFODLG.C < prev    next >
C/C++ Source or Header  |  1997-05-06  |  7KB  |  252 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993 - 1995  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE:   info.c
  9. //
  10. //  PURPOSE:   Displays the "Info" dialog box
  11. //
  12. //  FUNCTIONS:
  13. //    CmdInfo        - Displays the "Info" dialog box
  14. //    InfoProc       - Processes messages for "Info" dialog box.
  15. //    MsgInfoInit    - To initialize the about box with version info
  16. //                     from resources.
  17. //    MsgInfoCommand - Process WM_COMMAND message sent to the about box.
  18. //    CmdInfoDone    - Free the about box and related data.
  19. //
  20. //  COMMENTS:
  21. //
  22. //
  23.  
  24. #include <windows.h>            // required for all Windows applications
  25. #include <windowsx.h>
  26. #include <commctrl.h>
  27. #include "globals.h"            // prototypes specific to this application
  28. #include "infodlg.h"
  29.  
  30.  
  31. LRESULT CALLBACK InfoProc(HWND, UINT, WPARAM, LPARAM);
  32. LRESULT MsgInfoInit(HWND, UINT, WPARAM, LPARAM);
  33. LRESULT MsgInfoCommand(HWND, UINT, WPARAM, LPARAM);
  34. LRESULT CmdInfoDone(HWND, WORD, WORD, HWND);
  35.  
  36.  
  37. // Info dialog message table definition.
  38. MSD rgmsdInfo[] =
  39. {
  40.     {WM_COMMAND,    MsgInfoCommand},
  41.     {WM_INITDIALOG, MsgInfoInit}
  42. };
  43.  
  44. MSDI msdiInfo =
  45. {
  46.     sizeof(rgmsdInfo) / sizeof(MSD),
  47.     rgmsdInfo,
  48.     edwpNone
  49. };
  50.  
  51. // Info dialog command table definition.
  52. CMD rgcmdInfo[] =
  53. {
  54.     {IDOK,     CmdInfoDone},
  55.     {IDCANCEL, CmdInfoDone}
  56. };
  57.  
  58. CMDI cmdiInfo =
  59. {
  60.     sizeof(rgcmdInfo) / sizeof(CMD),
  61.     rgcmdInfo,
  62.     edwpNone
  63. };
  64.  
  65. // Module specific "globals"  Used when a variable needs to be
  66. // accessed in more than on handler function.
  67.  
  68.  
  69. //
  70. //  FUNCTION: CmdInfo(HWND, WORD, WORD, HWND)
  71. //
  72. //  PURPOSE: Displays the "Info" dialog box
  73. //
  74. //  PARAMETERS:
  75. //    hwnd      - Window handle
  76. //    wCommand  - IDM_INFO (unused)
  77. //    wNotify   - Notification number (unused)
  78. //    hwndCtrl  - NULL (unused)
  79. //
  80. //  RETURN VALUE:
  81. //
  82. //    Always returns 0 - Message handled
  83. //
  84. //  COMMENTS:
  85. //    To process the IDM_INFO message, call DialogBox() to display the
  86. //    InfoDlg dialog box.
  87.  
  88. #pragma argsused
  89. LRESULT CmdInfo(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  90. {
  91.     DialogBox(hInst, "InfoDlg", hwnd, (DLGPROC)InfoProc);
  92.     return 0;
  93. }
  94.  
  95.  
  96. //
  97. //  FUNCTION: InfoProc(HWND, UINT, WPARAM, LPARAM)
  98. //
  99. //  PURPOSE:  Processes messages for "Info" dialog box.
  100. //
  101. //  PARAMETERS:
  102. //    hdlg - window handle of the dialog box
  103. //    wMessage - type of message
  104. //    wparam - message-specific information
  105. //    lparam - message-specific information
  106. //
  107. //  RETURN VALUE:
  108. //    TRUE - message handled
  109. //    FALSE - message not handled
  110. //
  111. //  COMMENTS:
  112. //
  113. //     Display video device information
  114. //
  115. //     Wait for user to click on "Ok" button, then close the dialog box.
  116. //
  117.  
  118. LRESULT CALLBACK InfoProc(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
  119. {
  120.     return DispMessage(&msdiInfo, hdlg, uMessage, wparam, lparam);
  121. }
  122.  
  123.  
  124. //
  125. //  FUNCTION: MsgInfoInit(HWND, UINT, WPARAM, LPARAM)
  126. //
  127. //  PURPOSE: To initialize the about box with version info from resources.
  128. //
  129. //  PARAMETERS:
  130. //    hwnd - The window handing the message.
  131. //    uMessage - The message number. (unused).
  132. //    wparam - Message specific data (unused).
  133. //    lparam - Message specific data (unused).
  134. //
  135. //  RETURN VALUE:
  136. //    Always returns 0 - message handled.
  137. //
  138. //  COMMENTS:
  139. //    Uses GetDeviceCaps to query the driver for info regarding
  140. //    the display device's color and palette capabilities.
  141. //
  142.  
  143. #pragma argsused
  144. LRESULT MsgInfoInit(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
  145. {
  146.      HDC  hDC;
  147.      char szText[64];
  148.  
  149.     // Center the dialog over the application window
  150.     CenterWindow(hdlg, GetWindow(hdlg, GW_OWNER));
  151.  
  152.     // get screen DC
  153.     hDC = GetDC(NULL);
  154.     
  155.     // get various DeviceCaps
  156.     
  157.     // Palette-based device?
  158.     wsprintf(szText, "%s", (bPalDevice ? "Yes": "No"));
  159.     SetDlgItemText(hdlg, IDC_RCPALETTE, szText);
  160.  
  161.     if (bPalDevice)
  162.     {
  163.         wsprintf(szText, "%u", GetDeviceCaps(hDC, SIZEPALETTE));
  164.         SetDlgItemText(hdlg, IDC_SIZEPALETTE, szText);
  165.  
  166.         // This is the number of static colors reserved by Windows
  167.         wsprintf(szText, "%u", GetDeviceCaps(hDC, NUMRESERVED));
  168.         SetDlgItemText(hdlg, IDC_NUMRESERVED, szText);
  169.         
  170.         // This is the actual number of bits the device can use
  171.         // to represent colors. For example, the 8514/A uses
  172.           // 18 bit DACs: 6 bits for red, 6 for green, and 6 for blue.
  173.         wsprintf(szText, "%u", GetDeviceCaps(hDC, COLORRES));
  174.         SetDlgItemText(hdlg, IDC_COLORRES, szText);        
  175.     }
  176.     else
  177.     {
  178.         // not a palette device, so these aren't applicable
  179.         wsprintf(szText, "%s", "N/A");
  180.         SetDlgItemText(hdlg, IDC_SIZEPALETTE, szText);
  181.         SetDlgItemText(hdlg, IDC_NUMRESERVED, szText);
  182.         SetDlgItemText(hdlg, IDC_COLORRES, szText);
  183.     }
  184.  
  185.     wsprintf(szText, "%u", GetDeviceCaps(hDC, NUMCOLORS));
  186.     SetDlgItemText(hdlg, IDC_NUMCOLORS, szText);
  187.  
  188.     wsprintf(szText, "%u", GetDeviceCaps(hDC, BITSPIXEL));    
  189.     SetDlgItemText(hdlg, IDC_BITSPIXEL, szText);
  190.     
  191.     wsprintf(szText, "%u", GetDeviceCaps(hDC, PLANES));
  192.     SetDlgItemText(hdlg, IDC_PLANES, szText);
  193.                     
  194.     ReleaseDC(NULL, hDC);
  195.  
  196.      return TRUE;
  197. }
  198.  
  199. //
  200. //  FUNCTION: MsgInfoCommand(HWND, UINT, WPARAM, LPARAM)
  201. //
  202. //  PURPOSE: Process WM_COMMAND message sent to the about box.
  203. //
  204. //  PARAMETERS:
  205. //    hwnd - The window handing the message.
  206. //    uMessage - The message number. (unused).
  207. //    wparam - Message specific data (unused).
  208. //    lparam - Message specific data (unused).
  209. //
  210. //  RETURN VALUE:
  211. //    Always returns 0 - message handled.
  212. //
  213. //  COMMENTS:
  214. //    Uses this DipsCommand function defined in wndproc.c combined
  215. //    with the cmdiInfo structure defined in this file to handle
  216. //    the command messages for the about dialog box.
  217. //
  218.  
  219. #pragma argsused
  220. LRESULT MsgInfoCommand(HWND   hwnd,
  221.                                 UINT   uMessage,
  222.                                 WPARAM wparam,
  223.                                 LPARAM lparam)
  224. {
  225.     return DispCommand(&cmdiInfo, hwnd, wparam, lparam);
  226. }
  227.  
  228. //
  229. //  FUNCTION: CmdInfoDone(HWND, WORD, HWND)
  230. //
  231. //  PURPOSE: Free the about box and related data.
  232. //
  233. //  PARAMETERS:
  234. //    hwnd - The window handling the command.
  235. //    wCommand - The command to be handled (unused).
  236. //    wNotify   - Notification number (unused)
  237. //    hwndCtrl - NULL (unused).
  238. //
  239. //  RETURN VALUE:
  240. //    Always returns TRUE.
  241. //
  242. //  COMMENTS:
  243. //    Calls EndDialog to finish the dialog session.
  244. //
  245.  
  246. #pragma argsused
  247. LRESULT CmdInfoDone(HWND hdlg, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  248. {
  249.     EndDialog(hdlg, TRUE);          // Exit the dialog
  250.     return TRUE;
  251. }
  252.